local midao = fk.CreateSkill{
    name = "ld__midao",
    derived_piles = "ld__midao_rice",
}

local H = require "packages.ol_hegemony.util"

midao:addEffect(fk.EventPhaseStart,{
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(midao.name) then
            return target == player and player.phase == Player.Finish and #player:getPile("ld__midao_rice") == 0
        end
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player,{skill_name = midao.name, prompt = "#midao-invoke"})
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:drawCards(2, midao.name)
        if player:isNude() then return false end
        local cards = room:askToCards(player,{
            min_num = 2,
            max_num = 2,
            prompt = "#midao-cost",
            include_equip = true,
            skill_name = midao.name,
            cancelable = false,
        })
        player:addToPile("ld__midao_rice", cards, true, midao.name)
      end,
})

midao:addEffect(fk.EventPhaseStart,{
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(midao.name) and H.compareKingdomWith(target, player) and target.phase == Player.Play and #player:getPile("ld__midao_rice") > 0
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askToCards(player,{
        min_num = 1,
        max_num = 1,
        include_equip = false,
        pattern = ".|.|.|ld__midao_rice",
        skill_name = midao.name,
        prompt = "#ld__midao_choose::"..target.id,
        expand_pile = "ld__midao_rice",
        cancelable = true,
      })
    if #card > 0 then
      event:setCostData(self, {cards = card})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    player.room:moveCardTo(event:getCostData(self).cards, Card.PlayerHand, target, fk.ReasonGive, midao.name, "ld__midao_rice", true, player)
  end,
})


Fk:loadTranslationTable{
    ["ld__midao"] = "米道",
    [":ld__midao"] = "结束阶段开始时，若你没有“米”，你可以摸两张牌，若如此做，你将两张牌置于武将牌上，称为“米”；与你势力相同的角色的出牌阶段开始时，若你有“米”，你可以交给其一张“米”。",

    ["ld__midao_rice"] = "米",
    ["#midao-invoke"] = "米道：是否摸两张牌并将两张牌置于武将牌上",
    ["#midao-cost"] = "米道：将两张牌置为“米”",
    ["#ld__midao_choose"] = "米道：选择一张“米”，交给 %dest",

    ["$ld__midao1"] = "恩结天地，法惠八荒。",
    ["$ld__midao2"] = "行五斗米道，可知暖饱。",
 }

return midao